#include <ime.h>
typedef struct{
	int x;
	char* tmp;
} IC;
int init(char* param,void* ic)
{
	IM_LOG_INFO("*********Input Module Sample*************");
	return 0;
}
int OnSpacePressed(uint32_t sym,uint32_t state, uint32_t id,void* ic)
{
	IC* cont = (IC*)ic;
	if(cont->tmp == NULL) return FE_CLIENT;  //forward it
	char buf[1000];
	sprintf(buf,"%s ",cont->tmp);
	IMCommit(buf,ic);
	cont->tmp = NULL;
	return FE_SUCCEED;
}
int enable(void* context)
{
	IMSetTrayIcon("/usr/share/icons/gnome/32x32/actions/process-stop.png",context);
	static int i = 0;
	IC* ic = (IC*)context;
	ic->x = ++i;
	IM_LOG_INFO("********************************************%d",ic->x);
	IMRegisterForwardFilter(32,33,0xffff,0x0000,IMKeyActionPress,OnSpacePressed,ic);
	return 0;
}
int disable(void* context)
{
	IC* ic = (IC*) context;
	IM_LOG_INFO("%d",ic->x);
	return 0;
}
int changed(char* text,uint32_t len,void* ic)
{
	char tmp[1000];
	sprintf(tmp,"<span foreground=\"blue\">%s</span>",text);
	char * cand[] = {"<span foreground=\"red\">1.呃</span>","2.额","3.恶","4.饿"};
	IC* cont = (IC*) ic;
	IMUpdatePrecommitText(tmp, ic);
	IMUpdateCandidates(cand,4,ic);
	cont->tmp = text;
	return 0;
}
MetaDataBegin(Sample,IC,1)
	IMSetMetaData(NCandidates,10);
	IMRegisterEventHandler(OnInitialize,init);
	IMRegisterEventHandler(OnEnabled,enable);
	IMRegisterEventHandler(OnDisabled,disable);
	IMRegisterEventHandler(OnPreeditTextChanged,changed);
MetaDataEnd
